<template>
    <div>
		<div>
			<p style="font-size: large;">基地信息</p>
			<p ><label>基地名字：</label>{{ theBaseEvaluate.bname }}</p>
			<p ><label>所在城市：</label>{{ theBaseEvaluate.city }}</p>
			<p ><label>详细地址：</label>{{ theBaseEvaluate.location }}</p>
			<p ><label>联系电话：</label>{{ theBaseEvaluate.phone }}</p>
			<p><label>评分:</label>
				<el-tag style="margin-left: 10px;" v-for="(item,index) in basesEvaluate" :key="index"> {{ item.createTime }}年: {{item.score}} </el-tag>
			</p>
		</div>
		<div style="margin-top: 50px;">
			<p style="font-size: large;">开始评分</p>
			<el-form ref="scoreForm" :model="scoreInfo" :rules="rules">
				<el-form-item label="评分" prop="score">
					<el-input v-model="scoreInfo.score" style="width: 160px;" size="small" placeholder="请填写今年的评分"></el-input>
				</el-form-item>
			</el-form>
			<el-button style="margin-left: 8px;" size="small" type="primary"
					:disabled="theBaseEvaluate.createTime == new Date().getFullYear()" @click="doAdd" >提交</el-button>
			<p style="font-size: inherit;opacity: 0.4">(采用百分制评分：0-60为不合格；61-75为一般；76-90为良好；91-100为优秀)</p>
		</div>
        
		
    </div>
</template>

<script>
export default {
	data() {
		return {
			basesEvaluate: [],
			theBaseEvaluate: [],
			scoreInfo: {score:''},
			rules: {
				score: [{required: true, message: '请填写评分', trigger: 'blur'}],
			}
		}
	},
	mounted() {
		this.initBaseEvaluate();
	},
	methods:{
		initBaseEvaluate(){
			this.getRequest('/evaluate/base/').then(resp => {
				if(resp) {
					this.basesEvaluate = resp;
				}
			})
		},
		doAdd(){
			this.$refs['scoreForm'].validate(valid => {
				if (valid) {
					this.$confirm('此操作将提交评分,且一经提交无法修改, 是否继续?', '提示', {
						confirmButtonText: '确定',
						cancelButtonText: '取消',
						type: 'warning'
					}).then(() => {
						let theEvaluate = {};
						theEvaluate.bid = this.theBaseEvaluate.bid;
						theEvaluate.score = this.scoreInfo.score;
						this.postRequest('/evaluate/base/', theEvaluate).then(resp => {
							if (resp) {
								this.scoreInfo = {};
								this.initBaseEvaluate();
							}
						})
					}).catch(() => {
						this.$message({
							type: 'info',
							message: '已取消删除'
						});
					});
				}
			});
		},
	},
	watch:{
		basesEvaluate(){
			this.theBaseEvaluate = this.basesEvaluate[0];
		}, 
		immediate: true
	},
}
</script>

<style scoped>

</style>